# _*_ coding utf-8 _*_
# FILENAME：SelectProductionLineComponent.py
# DESCRIPTION: 生产线选择控件,基于QComboBox控件
# AUTH: jarvis zhang
# DATE: 2022/6/59:47 上午

from PyQt5.QtWidgets import *

from components.BaseComboBox import BaseComBoBox


class SelectProductionLineComponent(QComboBox):

    __data = None

    def __init__(self, parent=None):
        super(SelectProductionLineComponent, self).__init__()
        print("init")
        # self.__data = self.init_data()
        arr = []
        # for i in range(len(self.__data)):
        #     model = self.__data[i]
        #     val = model.name + '|' + str(model.id)
        #     arr.append(val)

        val1 = '焊装|1'
        val2 = '涂装|2'
        val3 = '总装|3'
        arr.append(val1)
        arr.append(val2)
        arr.append(val3)
        self.addItems(arr)
        self.__data = arr

    # def init_data(self):
    #     print("init data")
    #     model = FactoryModel()
    #     data = query(model)
    #     return data

    def getId(self):
        data = self.currentText()
        arr = data.split('|')
        return arr[1]

    def getText(self):
        data = self.currentText()
        arr = data.split('|')
        return arr[0]

    def selectedById(self, id=0):
        for i in range(len(self.__data)):
            data = self.__data[i]
            arr = data.split('|')
            if int(arr[1]) == id:
                self.setCurrentIndex(i)
                break